var contextPath = $("#contextPath").val();
(function(win, doc) {
  var html = '<ul><li class="sub_nav_item" id="shopCartFloat"><em style="display: none" class="n quantity_tips">0</em><a class="sub_nav_aims" href="'+contextPath+'/shoppingCart"><i class="icon_subnav_01"></i></a></li><li class="sub_nav_item sub_nav_ol"><ol><li class="sub_nav_item"><a class="sub_nav_aims" href="'+contextPath+'/"><i class="icon_subnav_02"></i></a></li><li class="sub_nav_item"><a class="sub_nav_aims" href="'+contextPath+'/user"><i class="icon_subnav_03"></i></a></li></ol></li><li class="sub_nav_item"><a class="sub_nav_aims" href="javascript:;"><i class="icon_subnav_04"></i></a></li></ul>',
    sub_nav = document.createElement('div');
  sub_nav.className = "sub_nav";
  sub_nav.innerHTML = html;
  document.body.appendChild(sub_nav);
  getShopCartNum();
  var btn = document.querySelectorAll('.sub_nav_aims'),
    ol = document.querySelector('.sub_nav_ol'),
    ht = ol.querySelector('ol').offsetHeight,
    index = btn.length - 1,
    is = true;
  btn[index].addEventListener('click', function() {
    if (is) {
      ol.style.height = ht + 'px';
      is = false;
    } else {
      ol.style.height = '0px';
      is = true
    }
  }, false);

}(window, document));
function getShopCartNum(){
	$.ajax({
		url:contextPath + '/common/getGoodsCount',
		type:'post',
		dataType:"json",
		success:function(data, textStatus){
			if(data.result.state == 1){
				var goodsNumber = data.goodsNum;
				$("#shopCartFloat").find('em').html(goodsNumber);
				if(goodsNumber > 0){
				$("#shopCartFloat").find('em').show();
				}
			}
		}
	});
	
}

